package com.example.springbatchdemo.config;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Classname ChildJob1
 * @Description TODO
 * @Date 2020/9/19 13:24
 * @Created by kevin
 */
@Configuration
public class ChildJob2 {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;
    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Bean
    public Job childJob2Job() {
        return jobBuilderFactory.get("childJob2Job")
                .start(childJob2Step1())
                .next(childJob2Step2())
                .build();
    }

    @Bean
    public Step childJob2Step1() {
        return stepBuilderFactory.get("childJob2Step1").tasklet(( StepContribution contribution, ChunkContext chunkContext ) -> {
            System.out.println("执行了childJob2Step1......");
            return RepeatStatus.FINISHED;
        }).build();
    }

    @Bean
    public Step childJob2Step2() {
        return stepBuilderFactory.get("childJob2Step2").tasklet(( StepContribution contribution, ChunkContext chunkContext ) -> {
            System.out.println("执行了childJob2Step2......");
            return RepeatStatus.FINISHED;
        }).build();
    }
}
